﻿@model Vitus.Featured.Models.FeaturedPart
@using Vitus.Featured
@using Vitus.Featured.Settings
@using Orchard.Utility.Extensions;
@using Orchard.Environment.Configuration

@{
    var settings = Model.Settings.GetModel<FeaturedSettings>();
    string controllerId = null;    
}   

@if (settings.Mode == FeaturedMode.AlwaysFeatured)
{
    <input type="hidden" name="@Html.FieldNameFor(m => m.IsFeatured)" value="true" />
}
else
{
    var isFeaturedChecked = Model.IsFeatured == true
        || Model.Id == 0 && settings.Mode == FeaturedMode.FeaturedByDefault;
        
    controllerId = Html.FieldIdFor(m => m.IsFeatured);
        
    <fieldset>
        <span class="checkbox-and-label">
            <input type="checkbox" name="@Html.FieldNameFor(m => m.IsFeatured)" id="@Html.FieldIdFor(m => m.IsFeatured)" checked="@isFeaturedChecked" value="true" />
            <input type="hidden" name="@Html.FieldNameFor(m => m.IsFeatured)" value="false" />
            <label for="@Html.FieldIdFor(m => m.IsFeatured)" class="forcheckbox">@T("Featured")</label>
        </span>
        <span class="hint">@T("Check to mark the content as featured.")</span>
    </fieldset>
}
    
<div data-controllerid="@controllerId">

    @if (settings.TitlePartUsageMode == FieldDependencyMode.UseAlways)
    {
        @Html.Hidden(Html.FieldNameFor(m => m.Title), "")
    }
    else {
        var featuredTitleRequired = settings.TitlePartUsageMode == FieldDependencyMode.Disallow;
            
        <fieldset>
            <label for="@Html.FieldIdFor(m => m.Title)" class="@(featuredTitleRequired ? "required" : null)">@T("Featured Title")</label>
            @Html.TextBoxFor(m => m.Title, new { @class = "large text" })
            @Html.ValidationMessageFor(m => m.Title)
            <span class="hint">@T("Title to be displayed in the Featured widget.") @(!featuredTitleRequired ? T("Leave empty if you want to use text from the TitlePart.") : null)</span>
        </fieldset>
    }
    
    @if (settings.BodyPartUsageMode == FieldDependencyMode.UseAlways)
    {
        @Html.Hidden(Html.FieldNameFor(m => m.Body), "")
    }
    else
    {
        var featuredBodyRequired = settings.BodyPartUsageMode == FieldDependencyMode.Disallow;
            
        <fieldset>
            <label for="@Html.FieldIdFor(m => m.Body)" class="@(featuredBodyRequired ? "required" : null)">@T("Featured Body")</label>
            @Html.TextAreaFor(m => m.Body, 5, 30, null)
            @Html.ValidationMessageFor(m => m.Body)
            <span class="hint">@T("Text to be displayed in the Featured widget.") @(!featuredBodyRequired ? T("Leave empty if you want to use text from the BodyPart.") : null)</span>
        </fieldset>
    }

    <fieldset>
        <span class="checkbox-and-label">
            @Html.CheckBoxFor(m => m.IsPinned)
            <label for="@Html.FieldIdFor(m => m.IsPinned)" class="forcheckbox">@T("Pinned")</label>
        </span>
        <span class="hint">@T("Pinned content displays always on top of the other content, no matter the publishing date.")</span>
    </fieldset>
</div>